{extend name="layout" /}

{block name="title"}
<title>详情页面Join查询配置 - thinkPHP极速后台开发</title>
<meta name="title" content="详情页面Join查询配置 - thinkPHP极速后台开发">
<meta name="keywords" content="详情页面Join查询配置,php,后台开发包，thinkphp、easyadmin、admin,easy,thinkeasyadmin">
<meta name="description" content="详情页面Join查询配置;详情页面 JOIN 查询跟列表是相似的,只需要配置 join 查询方法;easyadmin灵活可定制的thinkphp的后台开发工具包,助你快速开发后台">
{/block}

{block name="main"}


<fieldset id="join" class="layui-elem-field">
    <legend>详情页面 JOIN 查询</legend>
    <div class="layui-field-box">
        <p>详情页面 JOIN 查询跟列表是相似的,只需要配置 join 查询方法</p>
        <pre class="php">{literal}
#project\app\admin\controller\Category.php

namespace app\admin\controller;
use easyadmin\app\libs\PageShow;
use think\db\Query;

class Category extends \easyadmin\controller\Admin
{


    /**
     * 配置详情页面字段
     * @param ListField $field
     */
    protected function configShowField(ListField $field)
    {
        $field
            ->addField('id', 'ID', ListText::class)
            # 根据 join 查询指定的别名来
            ->addField('c.name', '上级分类', ListText::class, [
                'default' => '顶级分类'
            ])
            ->addField('name', '分类名称', ListText::class)
            ->addField('intro', '分类简介', ListText::class)
            ->addField('icon', '分类图标', ListImage::class)
            ->addField('time', '创建时间', ListDateTime::class)
            ->addField('is_del', '是否删除', ListSwitch::class);
    }



    /**
     * 详情的查询语句
     * @param Query $query
     * @param $alias
     */
    protected function configShowQuery(Query $query, $alias)
    {
        // 指定别名是 c    指端声明处 也要用 c
        $query->join('category c', "c.id = {$alias}.parent_id", 'LEFT');
    }

}

{/literal}</pre>
    </div>
</fieldset>



{/block}
